﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Foothill.Privilege.Utils;

namespace GGFW.Web
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-99);
            Response.Expires = 0;
            Response.CacheControl = "no-cache";

            if (!Page.IsPostBack)
            {
                HttpCookie cookie = Request.Cookies["GGFW"];
                if (cookie != null)
                {
                    txtUserName.Text = cookie.Value;
                }

            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            int loginResult = PrivilegeHttpUtil.Login(txtUserName.Text, this.txtPasswrd.Text);

            if (loginResult < 0)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "err", "<script>alert('用户不存在或密码不正确!');</script>");
                return;
            }

            Session.Timeout = 60 * 24;

            //记录cookie
            HttpCookie cookie = new HttpCookie("GGFW");
            cookie.Value = txtUserName.Text.Trim();

            DateTime d = DateTime.Now.AddDays(30);//30天过期
            cookie.Expires = d;
            Response.Cookies.Add(cookie);

            Response.Redirect("Default.aspx");
        }
    }
}
